﻿using System.Text.RegularExpressions;
using ValueOf;

namespace Customers.Api.Domain.Common;

public class GitHubUsername : ValueOf<string, GitHubUsername>
{
    private static readonly Regex UsernameRegex = new("^[a-z\\d](?:[a-z\\d]|-(?=[a-z\\d])){0,38}$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

    protected override void Validate()
    {
        if (!UsernameRegex.IsMatch(Value))
        {
            this.ThrowValidationException(nameof(GitHubUsername), $"{Value} is not a valid username");
        }
    }
}